package com.vvv.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.vvv.shortlink.project.dao.entity.LinkLocalStatsDO;
import com.vvv.shortlink.project.dto.req.LinkStatsReqDTO;
import com.vvv.shortlink.project.dto.resp.LinkStatsLocaleCNRespDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
* @author Dell
* @description 针对表【t_link_locale_stats】的数据库操作Mapper
* @createDate 2024-02-20 16:25:16
* @Entity generator.domain.LinkLocaleStats
*/
public interface LinkLocaleStatsMapper extends BaseMapper<LinkLocalStatsDO> {

    @Insert("INSERT INTO t_link_local_stats (full_short_url, user_id, date, province, city, adcode, country, cnt) " +
            "VALUES(#{linkLocalStatsDO.fullShortUrl}, #{linkLocalStatsDO.userId}, #{linkLocalStatsDO.date}, #{linkLocalStatsDO.province}, #{linkLocalStatsDO.city}, #{linkLocalStatsDO.adcode}, #{linkLocalStatsDO.country}, #{linkLocalStatsDO.cnt}) " +
            "ON DUPLICATE KEY UPDATE " +
            "cnt = cnt + #{linkLocalStatsDO.cnt}")
    void monitorShortLink(@Param("linkLocalStatsDO") LinkLocalStatsDO linkLocalStatsDO);

    /**
     * 以省份分组，获取范围时间内每个省的总访问量cnt
     * @param requestParam
     * @return
     */
    List<LinkStatsLocaleCNRespDTO> listLocalStatsGroupByProvince(@Param("requestParam") LinkStatsReqDTO requestParam);
}




